package com.right.health.app.hyphenate;

import android.util.Log;

import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.exceptions.HyphenateException;

/*
 * Created by hopeliao on 2019-12-24
 *
 */
public class EMClientHelper {

    private static EMClientHelper sHelper;

    static {
        sHelper = new EMClientHelper();
    }

    private EMClientHelper() {

    }

    public static EMClientHelper getInstance() {
        return sHelper;
    }

    public boolean createCount(String username, String pwd) {
        try {
            EMClient.getInstance().createAccount(username, pwd);
        } catch (HyphenateException e) {
            e.printStackTrace();
            return false;
        }
        Log.e("TAG", "EM Create Account Succ, username = " + username);
        return true;
    }

    public void login(String username, String pwd) {
        EMClient.getInstance().login(username,pwd,new EMCallBack() {//回调
            @Override
            public void onSuccess() {
                EMClient.getInstance().groupManager().loadAllGroups();
                EMClient.getInstance().chatManager().loadAllConversations();
                Log.e("TAG", "登录聊天服务器成功！");


            }

            @Override
            public void onProgress(int progress, String status) {

            }

            @Override
            public void onError(int code, String message) {
                Log.e("TAG", "登录聊天服务器失败！");
            }
        });
    }

    public void logout() {
        EMClient.getInstance().logout(true);
    }
}
